const { ccclass, property, menu, executeInEditMode } = cc._decorator;
@ccclass
@menu(`${PropControllor.name}`)
export default class PropControllor extends cc.Component {

    @property
    propertyJson: string = "";

    onLoad() {
        this.init();
    }

    init() {
        this.saveStruction();

    }

    /** 遍历自身及子节点 */
    saveStruction() {
        if (CC_EDITOR) {
            let parent = _getRoot(this.node);
            print(parent.name);
            Editor.Scene.callSceneScript('build_worker', 'print', parent.uuid)
        }
    }

}
// 获取根节点
function _getRoot(node) {
    print('_getRoot');
    let parent = node;
    while (parent && parent.parent /*&& !(parent.parent instanceof cc.Scene)*/) {
        parent = parent.parent;
        print('parent', parent)
    }
    return parent;
}

function print(key, value?) {
    if (CC_EDITOR) {
        Editor.log(key, value)
    } else {
        console.log(key, value)
    }
}
